var selectedRow = '';
var isInit = true;

$(function () {
    window.actionEvents = {
        'click .isvInfoView': function(e, value, row, index) {
            //编辑操作
            selectedRow = row;
            console.log(row);
            openCommonIsvPage(row.isvPid, 'checkBizDocApp');
        },
    }
    initTextSearch("#isvName",
        basePath + 'checkBizDocApp/getIsvData?t='+new Date().getTime()+'&isvName=',
        ['isvPid', 'isvName'],
        {'isvPid':'服务商PID', 'isvName':'服务商名称'},
        'isvPid',
        'isvName',
        true,
        selectIsvValue,
        noSelectIsvValue,
        false);
    // initTextSearch("#orgName2",
    //     basePath + 'checkBizDocApp/getOrgData?t='+new Date().getTime()+'&orgName=',
    //     ['orgCode', 'orgName'],
    //     {'orgCode':'机构编码', 'orgName':'机构名称'},
    //     'orgCode',
    //     'orgName',
    //     true,
    //     selectOrgValue,
    //     noSelectOrgValue,
    //     false);
    /*laydate.render({
        elem: '#beginTimeStr'
        ,done: function(value, date, endDate){
            //控件选择完毕后的回调
            //点击日期、清空、现在、确定均会触发。回调返回三个参数，分别代表：生成的值、日期时间对象、结束的日期时间对象
            // setAge(value);
        }
    });
    laydate.render({
        elem: '#endTimeStr'
        ,done: function(value, date, endDate){
            //控件选择完毕后的回调
            //点击日期、清空、现在、确定均会触发。回调返回三个参数，分别代表：生成的值、日期时间对象、结束的日期时间对象
            // setAge(value);
        }
    });*/
    laydate.render({
        elem: '#timeInterval'
        ,type: 'datetime'
        ,range: true //或 range: '~' 来自定义分割字符
        // ,value: dateFtt("yyyy-MM-dd hh:mm:ss", preDate) + ' - ' + dateFtt("yyyy-MM-dd hh:mm:ss", curDate)
        //js赋值重置失效，改为就是怕、页面赋值
        ,isInitValue: true //是否允许填充初始值，默认为 true
    });
});

function selectIsvValue(data) {
    if (!data || !data.isvPid) {
        return;
    }
    $('#isvPid').val(data.isvPid);
}

function noSelectIsvValue() {
    $('#isvPid').val('');
}

function selectOrgValue(data) {
    if (!data || !data.orgCode) {
        return;
    }
    $('#orgCode').val(data.orgCode);
}

function noSelectOrgValue() {
    $('#orgCode').val('');
}


function doRefresh() {
    selectedRow = '';
    $('#dataTable').bootstrapTable('refresh', {
        url: basePath + 'checkOrgApp/pageFindPendingCheckOrgAppData?t=' + new Date().getTime(),
    });
}

function getParams(params) {
    var pageSize = params.pageSize;
    var pageNo = params.pageNumber;
    if (isInit) {
        isInit = false;
        pageSize = searchInfo.pageSize ? searchInfo.pageSize : params.pageSize;
        pageNo = searchInfo.pageNo ? searchInfo.pageNo : params.pageNumber;
    }
    var postData ={
        pageSize : pageSize,
        pageNo : pageNo
    };
    var gmtStart = '';
    var gmtEnd = '';
    var timeInterval = $("#timeInterval").val();
    if(timeInterval){
        var dates = timeInterval.split(' - ');
        if(dates && dates.length >1){
            gmtStart = dates[0];
            gmtEnd = dates[1];
        }
    }
    postData.orgName =$.trim($("#orgName").val());
    postData.checkType =$.trim($("#checkType").val());
    postData.isvPid =$.trim($("#isvPid").val());
    postData.checkType =$.trim($("#checkType").val());
    postData.beginTimeStr =gmtStart;
    postData.endTimeStr =gmtEnd;
    postData.bizCode =$.trim($("#bizCode").val());
    return postData;
}

function openCheckDocPage() {
    if (!selectedRow.id || selectedRow.id == '') {
        toastr.error(common_no_choose_msg.format("操作"));
        return;
    }
    console.log(selectedRow.bizCode);
    var tableOptions = $('#dataTable').bootstrapTable('getOptions', null);
    console.log(selectedRow.appidStr);
    window.location.href = basePath + 'checkOrgApp/pendingCheckOrgPageWin?id=' + selectedRow.id
        +'&bizCodeApp=' + selectedRow.bizCodeApp+
        '&appid=' + selectedRow.appidStr +"&batchId="+selectedRow.batchId+ '&isQueryExist=' + searchInfo.isQueryExist +
        '&type=wait' + "&orgCode="+selectedRow.orgCode+ '&t=' + new Date().getTime() + '&' + $('#searchForm').serialize() + '&pageNo=' + tableOptions.pageNumber + '&pageSize=' + tableOptions.pageSize;
}

function formatOperateType(value, row, index) {
    return convertMapCodeText(OperateType,value);
}

$("#dataTable").on("click-row.bs.table",function(e,row,ele){
    $("#dataTable .success").removeClass("success");
    $(ele).addClass("success");
    selectedRow = row;
});

// $('#dataTable').on("dbl-click-row.bs.table", function (e, row, $element) {
//     window.location.href = basePath + 'checkOrgApp/pendingCheckOrgPageWin?id=' + selectedRow.id+
//         '&appid=' + selectedRow.appidStr +
//         "&batchId="+selectedRow.batchId+
//         "&orgCode="+selectedRow.orgCode+
//         '&type=wait' + '&t=' + new Date().getTime() + '&' + $('#searchForm').serialize() + '&pageNo=' + tableOptions.pageNumber + '&pageSize=' + tableOptions.pageSize;
// });